﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Project.Core.IServices;
using Project.Core.IServices.System;
using Project.Core.Model;
using Project.Core.Model.System;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Project.Core.Api.Controllers
{
    /// <summary>
    /// Controller
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    [Authorize]
    //[ApiExplorerSettings(IgnoreApi = true)]//让整个接口不显示在文档
    //[Authorize(Policy = "Client")]
    //[Authorize(Roles = "Admin,Client")]
    public class ValuesController : Controller
    {
        private IUserService _iUserService;
        private IUserRoleService _iUserRoleService;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="userService">用户Service</param>
        /// <param name="userRoleService">用户角色Service</param>
        public ValuesController(IUserService userService, IUserRoleService userRoleService)
        {
            _iUserService = userService;
            _iUserRoleService = userRoleService;
        }
        /// <summary>
        /// 获取列表
        /// </summary>
        /// <returns></returns>
        // GET api/values
        [HttpGet]
        // [AllowAnonymous]//不受授权控制，任何人都可访问
        // [Route("GetUsers")]
        public async Task<JsonResult> GetUsers()
        {
            var list = await _iUserService.Query(k => k.IsValid);
            return Json(list);
        }

        /// <summary>
        /// 获取单个
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        // GET api/values/5
        [HttpGet("{id}")]
        public ActionResult<string> Get(int id)
        {
            return "value";
        }

        /// <summary>
        /// 提交
        /// </summary>
        /// <param name="Entity"></param>
        // POST api/values
        [HttpPost]
        public void Post(User Entity)
        {
            var result = _iUserService.Add(Entity);
            // var result = _iUserRoleService.Add(Entity);
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="id"></param>
        /// <param name="value"></param>
        // PUT api/values/5
        [HttpPut("{id}")]
        public void Put(int id, [FromBody] string value)
        {
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        // DELETE api/values/5
        //[ApiExplorerSettings(IgnoreApi = true)]  //让某些接口不显示在文档
        [HttpDelete("{id}")]
        public void Delete(int id)
        {
        }
    }
}
